(function($){
    $.fn.zyslide = function(options){
        var defaults = {
		    speed: 2000
        }

        var settings = $.extend(defaults,options);
        // console.log(settings);
        return this.each(function(){
            var $this = $(this);
            var lis = $this.find('.slide').children();
            var indicators = $this.find('.indicator').children();

            var index = 0
            function next(){
                index = index==lis.length-1 ? 0 : index+1
                show()
            }
            function prev(){
                index = index==0 ? lis.length-1 : index-1;
                show();
            }
            function show(){
                lis.eq(index).fadeIn(500).siblings().fadeOut();
                indicators.eq(index).addClass('active').siblings().removeClass('active');
            }

            // 1.自动切换
            if(settings.speed){
                var timer = setInterval(next,settings.speed);
                $this.hover(function(){
                    clearInterval(timer);
                    timer = null;
                },function(){
                    if(timer) return;
                    timer = setInterval(next,settings.speed);
                });
            }
            

            // 2.点击指示灯切换
            indicators.on(settings.event,function(){
                index = $(this).index();
                show();
            });

            // 3.点击按钮切换
            $this.find('.prev').click(function(){
                prev();
            });
            $this.find('.next').click(function(){
                next();
            });
            
        });
    }
})(jQuery);



(function($){
    $.fn.zyclickslide = function(options){
        var defaults = {
		    speed: 2000
        }

        var settings = $.extend(defaults,options);
        return this.each(function(){
            var $this = $(this);
            var lis = $this.find('.slide').children();
            var indicators = $this.find('.indicator').children();

            var index = 0;
            function next(){
                index = index>=lis.length-1 ? lis.length-1 : index+1;
                show();
            }
            function prev(){
                index = index<=0 ? 0 : index-1;
                show();
            }
            function show(){
                $this.find('.slide').animate({left:-296*index},300);
                indicators.eq(index).addClass('active').siblings().removeClass('active')
            }
            // 1.点击按钮切换
            $this.find('.prev').click(function(){
                prev();
            });
            $this.find('.next').click(function(){
                next();
            });
            // 2.点击指示灯切换
            indicators.on(settings.event,function(){
                index = $(this).index();
                show();
            });


        });
    }
})(jQuery);